package com.hua.fanqiemall.product.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.hua.fanqiemall.product.vo.AttrRspVo;
import com.hua.fanqiemall.product.vo.AttrReqVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hua.fanqiemall.product.service.AttrService;
import com.hua.common.utils.PageUtils;
import com.hua.common.utils.R;



/**
 * 商品属性
 *
 * @author luoweihua
 * @email lwh_559@163.com
 * @date 2021-12-09 22:14:01
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    private static final Logger logger = LoggerFactory.getLogger(AttrController.class);

    /**
     * 查询商品属性接口
     * @author luoweihua
     * @date 2022/1/12 9:28
     * @param params 查询参数
     * @param catelogId 分类ID
     * @param attrType 属性类型：base-基本属性，sale-销售属性
     * @return R
     */
    @GetMapping("/{attrType}/list/{catelogId}")
    public R baseAttrList(@RequestParam Map<String, Object> params , @PathVariable("catelogId") Long catelogId , @PathVariable("attrType") String attrType){
        logger.info("查询商品属性接口：入参{},分类id：{},查询类型：{}",params,catelogId,attrType);
        PageUtils page = attrService.queryBaseAttrPage(params , catelogId , attrType);
        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    //@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){

        AttrRspVo attr = attrService.getAttrInfo(attrId);

        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrReqVo attrReqVo){
		attrService.saveAttr(attrReqVo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrReqVo attrReqVo){
		attrService.updateAttr(attrReqVo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
